package com.example.guessthesoundtrack;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.view.MotionEvent;

public class Button extends Sprite {
	private Paint paint;
	
	private String text;
	
	public Button(Bitmap clicked, Bitmap unclicked, String text, float x, float y, float width, float height) {
		super(clicked, unclicked, new Rect((int)x, (int)y, (int)(x + width), (int)(y + height)), x, y, width, height);
		this.text = text;

		this.paint = new Paint();
		this.paint.setTextSize(24f);
		this.paint.setTextAlign(Align.LEFT);
		this.paint.setColor(Color.WHITE);
		this.paint.setTypeface(Typeface.DEFAULT_BOLD);
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	@Override
	public void draw(Canvas canvas) {
		canvas.drawBitmap((isDown() ? getClicked() : getUnclicked()), null, getRect(), null);
		canvas.drawText(text, getX() + (getWidth() / 20f), getY() + (getHeight() / 2f) + (paint.getTextSize() / 4f) + ((getHeight() * 0.140625f / 2f) * (isDown() ? 1 : -1)), paint);
	}

	@Override
	public void update(int delta) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onClick(MotionEvent event, float x, float y) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isColliding(float x, float y) {
		return (x >= getX() && y >= getY() & x <= getX() + getWidth() && y <= getY() + getHeight());
	}
}